/*
 * Copyright (c) 2015 LingoChamp Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.living.filedownloader.ui.batch;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.living.R;
import com.living.filedownloader.DownLoadManger;
import com.living.filedownloader.bean.TasksManagerModel;
import com.living.filedownloader.ui.TasksDownloadingActivity;
import com.living.filedownloader.ui.adapter.TaskItemDownloadedAdapter;
import com.living.widget.BottomMenuView;
import com.md.livingwidget.CoreBaseActivity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 已下载 批量的操作
 * 操作
 */
public class DownloadBatchActivity extends CoreBaseActivity {

    BottomMenuView bottom_menu;
    AudioBatchFragment audioBatchFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_batch_delete);
        FragmentManager fragmentManager = getSupportFragmentManager();
        audioBatchFragment = (AudioBatchFragment) fragmentManager.findFragmentById(R.id.fm_batch_delete);

        bottom_menu = findViewById(R.id.bottom_menu);
        bottom_menu.setMenuShows(true, false, false, true);
        bottom_menu.setMenuAddEnable(false);

        audioBatchFragment.setOnBatchSelectLisenter(new AudioBatchFragment.OnBatchSelectLisenter() {
            @Override
            public void onSelect(int count, int total) {
                if (count > 0) {
                    bottom_menu.setMenuAddEnable(true);
                    bottom_menu.setMenuDeleteEnable(true);
                } else {
                    bottom_menu.setMenuAddEnable(false);
                    bottom_menu.setMenuDeleteEnable(false);
                }
            }
        });
        bottom_menu.setOnBottomMenuViewClick(new BottomMenuView.OnBottomMenuViewClick() {
            @Override
            public void onClickAdd(View view) {
                Toast.makeText(getmActivity(), "去李越专辑添加页面", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onClickDownload(View view) {

            }

            @Override
            public void onClickShare(View view) {
                Toast.makeText(getmActivity(), "分享组件", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onClickDelete(View view) {
                Map<String, TasksManagerModel> mapSel = audioBatchFragment.getMapSel();
                if (mapSel.size() > 0) {
                    //遍历map中的值
                    for (TasksManagerModel value : mapSel.values()) {
                        mapSel.remove(value);
                        audioBatchFragment.remove(value);
                        DownLoadManger.getInstance().deleteAudio(value.getAlbumId(), value.getAudioId(), value.getUrl());
                    }
                } else {
                    Toast.makeText(getmContext(), "请选择要删除的", Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v.getId() == R.id.layout_downloading) {
            startActivity(new Intent(this, TasksDownloadingActivity.class));
        } else if (v.getId() == R.id.iv_downloaded_edite) {

        }
    }


    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
